Repository navigation
Conversation
Documentation build overview
10 files changed ·
|
`await f()` on an async def, and async def __aenter__() and __aexit__() of async with, no longer create a coroutine object unless the body suspends. The compiler pushes a NULL lazy_outcome below the callable and follows the call with the new END_AWAITED_CALL instruction, which continues with GET_AWAITABLE, skips the SEND loop if the body returned, or creates the coroutine and jumps to YIELD_VALUE if it suspended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
asvetlov
force-pushed
the
claude/lazy-coroutine-materialization-5e5705
branch
from
November 20, 2026 18:40
81c138a to
e7c3c9b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A coroutine that is awaited as soon as it is called (
await f()), and anasync def__aenter__()or__aexit__()ofasync with, no longer creates a coroutine object unless it suspends. Awaits that complete immediately become about twice as fast.The compiler emits a new
END_AWAITED_CALLinstruction after an awaited call. When it follows, theCALLfamily runs a coroutine body without creating the coroutine object, andEND_AWAITED_CALLhandles the outcome. New*_AWAITEDspecializations ofCALLandCALL_KWcover awaited calls of Python functions.Until such a coroutine first suspends,
frame.f_generatorisNone.Calls from C, profiling and monitoring of calls, PEP 523, coroutine origin tracking and the JIT keep the current behavior.
await noop()async with asyncio.Lock()🤖 Generated with Claude Code